package demo2;

import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-08-11
 * Time: 16:48
 */
public class TestDemo5 {
    //创建一个可以执行一个单线程任务并且可以延迟时间的线程池
    public static void main(String[] args) {
        ScheduledExecutorService threadPool = Executors.newSingleThreadScheduledExecutor();
        System.out.println("当前加入任务时间"+new Date());
        threadPool.schedule(new Runnable() {
            @Override
            public void run() {
                System.out.println("执行任务时间"+ new Date());
            }
        },1, TimeUnit.SECONDS);
    }

}
